package com.alibaba.springboot.health.service.impl;

import com.alibaba.springboot.health.dao.RegisterOrderDao;
import com.alibaba.springboot.health.pojo.RegisterOrder;
import com.alibaba.springboot.health.service.RegisterOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (RegisterOrder)表服务实现类
 *
 * @author makejava
 * @since 2019-12-28 20:08:34
 */
@Service("registerOrderService")
public class RegisterOrderServiceImpl implements RegisterOrderService {
    @Autowired
    private RegisterOrderDao registerOrderDao;

    /**
     * 添加订单
     * @param registerOrder
     * @return
     */
    @Override
    public int add(RegisterOrder registerOrder) {
        return registerOrderDao.add(registerOrder);
    }

    @Override
    public List<RegisterOrder> findAll(String username) {
        return registerOrderDao.findAll(username);
    }

    @Override
    public List<RegisterOrder> findLimitOrder(int startIndex, int i, String username) {
        return registerOrderDao.findLimitOrder(startIndex,i,username);
    }

    @Override
    public List<RegisterOrder> findLimitUser(int startIndex, int limit, String name) {
        return registerOrderDao.findLimitOrder(startIndex, limit, name);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param orderId 主键
     * @return 实例对象
     */
    @Override
    public RegisterOrder queryById(Integer orderId) {
        return registerOrderDao.queryById(orderId);
    }
    
    
    /**
     * 查询多条数据
     * @param page 页码
     * @param pageSize 页大小
     * @param registerOrder 实体
     * @return PageInfo<RegisterOrder> 分页数据集合
     */
    @Override
    public PageInfo<RegisterOrder> queryAll(int page, int pageSize, RegisterOrder registerOrder) {
        /*拦截分页信息*/
        PageHelper.startPage(page, pageSize);

        List<RegisterOrder> registerOrderList = registerOrderDao.queryAll(registerOrder);

        return new PageInfo<>(registerOrderList);
    }

    /**
     * 新增数据
     *
     * @param registerOrder 实例对象
     * @return 实例对象
     */
    @Override
    public RegisterOrder insert(RegisterOrder registerOrder) {
        registerOrderDao.insert(registerOrder);
        return registerOrder;
    }

    /**
     * 修改数据
     *
     * @param registerOrder 实例对象
     * @return 实例对象
     */
    @Override
    public RegisterOrder update(RegisterOrder registerOrder) {
        registerOrderDao.update(registerOrder);
        return queryById(registerOrder.getOrderId());
    }

    /**
     * 通过主键删除数据
     *
     * @param orderId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer orderId) {
        return registerOrderDao.deleteById(orderId) > 0;
    }


}